package solutions.leetcode.easy;

import solutions.lib.BaseSolution;

import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;

/**
 * @author lizhidong
 * <a href="https://leetcode-cn.com/problems/relative-ranks/">506.相对名次</a>
 */
public class Solution506 extends BaseSolution {

    public String[] findRelativeRanks(int[] score) {
        String[] desc = {"Gold Medal", "Silver Medal", "Bronze Medal"};

        PriorityQueue<int[]> queue = new PriorityQueue<>((m1, m2) -> m2[0] - m1[0]);
        for (int i = 0; i < score.length; i++) {
            queue.offer(new int[]{score[i], i});
        }
        String[] ans = new String[score.length];
        int[] model;
        int p = 0;
        while ((model = queue.poll()) != null) {
            ans[model[1]] = p < 3 ? desc[p] : String.valueOf(p + 1);
            p++;
        }
        return ans;
    }

    public static void main(String[] args) {
        Solution506 solution = new Solution506();
        printVals(solution.findRelativeRanks(new int[] {10,3,8,9,4}));
    }
}